from pymongo import MongoClient

def getdb ():
	client=MongoClient(
		host='localhost',
		port=27017
	)
	db = client['hello']
	print('-'*30)
	print(f'db',db)
	print('-'*30)
	return db

def add(db,table,data):
	if isinstance(data,dict):
		db[table].insert_one(data)
	else:
		db[table].insert_many(data)

def upd(db,table,condition,next):
	db[table].update_one(condition, {"$set":next})

def delt(db,table,condition):
	db[table].delete_many(condition)

def find(db,table,condition):
	db[table].find(condition)

if __name__ == '__main__':
	db=getdb()
	d={
		'file':'http://localhost:8000/0240902212049.jpg',
		'filename':'睁眼看世界',
		'user':'湾湾',
		'level':13
	}
	t=({
		'file':'http://localhost:8000/0240902212049.jpg',
		'filename':'睁眼看世界22',
		'user':'湾湾',
		'level':1
	},{
		
		'file': 'http://localhost:8000/0240902212049.jpg',
		'filename': '睁眼看世界11',
		'user': '湾湾',
		'level': 11
	})
	# add(db,'uploadInfo',d)
	# add(db,'uploadInfo',t)
	n={
		'file':'0240902212049.jpg',
		'filename':'睁1眼看世界',
		'user':'湾~湾',
		'level':10
	}
	
	# upd(db,'uploadInfo',{'filename':'测试'},n)
	delt(db,'uploadInfo',{'filename':None})